﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
namespace Gaea
{
    public partial class GaeaBasicPower<T> : GaeaBasicPower where T : class, IGaeaSon
    {

        [Obsolete("之后会进行成重构")]
        public virtual IEnumerable<T> FindAll(int? commandTimeout = null)
        {
            return base.FindAll<T>(commandTimeout: commandTimeout);
        }

        [Obsolete("之后会进行成重构")]
        public virtual IEnumerable<T> FindAll(GaeaSort gaeaSort)
        {
            return base.FindAll<T>(sort: gaeaSort);
        }

        /// <summary>
        ///  查询多行记录
        /// </summary>
        /// <param name="commandText">T-SQL</param>
        /// <param name="parameters">参数</param>
        /// <param name="commandTimeout">执行超时时间</param>
        /// <returns>对应类型结果集</returns>
        public virtual IEnumerable<T> Find(string commandText, object parameters, int? commandTimeout = null)
        {
            return base.Find<T>(commandText, parameters, commandTimeout: commandTimeout);
        }

        /// <summary>
        /// 查询单条记录（如果查询记录出现多条则抛出异常）
        /// </summary>
        /// <param name="commandText">T-SQL</param>
        /// <param name="parameters">参数</param>
        /// <param name="commandTimeout">执行超时时间</param>
        /// <returns>结果</returns>
        public virtual T FindOne(string commandText, object parameters, int? commandTimeout = null)
        {
            return base.FindOne<T>(commandText, parameters);
        }

        /// <summary>
        /// 查询单条记录（如果查询记录出现多条则抛出异常）多用于事务
        /// </summary>
        /// <param name="dbConnection">Db Connection</param>
        /// <param name="commandText">T-SQL</param>
        /// <param name="parameters">参数</param>
        /// <param name="commandTimeout">超时时间</param>
        /// <returns>结果</returns>
        public virtual T FindOne(IDbConnection dbConnection, string commandText, object parameters, int? commandTimeout = null)
        {
            return base.FindOne<T>(dbConnection, commandText, parameters, commandTimeout: commandTimeout);
        }

        /// <summary>
        /// Id 查询出对应结果并映射
        /// </summary>
        /// <param name="id">内部唯一编号</param>
        /// <param name="commandTimeout">超时时间</param>
        /// <returns>映射类型</returns>
        public virtual T FindById(int id, int? commandTimeout = null)
        {
            return base.FindById<T>(id, commandTimeout);
        }

        /// <summary>
        /// Id 查询出对应结果并映射 多用于事务
        /// </summary>
        /// <param name="dbConnection">Db Connection</param>
        /// <param name="id">内部唯一编号</param>
        /// <param name="commandTimeout">超时时间</param>
        /// <returns>映射类型</returns>
        public virtual T FindById(IDbConnection dbConnection, int id, int? commandTimeout = null)
        {
            return base.FindById<T>(dbConnection, id, commandTimeout);
        }

        /// <summary>
        /// 数据插入操作
        /// </summary>
        /// <param name="son">实例</param>
        /// <returns>影响行数</returns>
        public virtual int Insert(T son)
        {
            return base.Insert(son);
        }

        /// <summary>
        /// 数据插入操作 多用于事务
        /// </summary>
        /// <param name="dbConnection">Db Connection</param>
        /// <param name="son">实例</param>
        /// <returns>影响行数</returns>
        public virtual int Insert(IDbConnection dbConnection, T son)
        {
            return base.Insert(dbConnection, son);
        }

        /// <summary>
        /// 更新数据操作
        /// </summary>
        /// <param name="son">实例</param>
        /// <returns>影响行数</returns>
        public virtual int Update(T son)
        {
            return base.Update(son);
        }

        /// <summary>
        /// 更新数据库操作 多用于事物
        /// </summary>
        /// <param name="dbConnection">Db Connection</param>
        /// <param name="son">实例</param>
        /// <returns>影响行数</returns>
        public virtual int Update(IDbConnection dbConnection, T son)
        {
            return base.Update(dbConnection, son);
        }

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="commandText">T-SQL</param>
        /// <param name="sons">实例集合</param>
        /// <returns>影响行数</returns>
        public virtual int BatchInsert(string commandText, IEnumerable<T> sons)
        {
            return base.BatchInsert(commandText, sons);
        }

        /// <summary>
        /// 批量插入 多用于事物
        /// </summary>
        /// <param name="dbConnection">Db Connection</param>
        /// <param name="commandText">T-SQL</param>
        /// <param name="sons">实例集合</param>
        /// <returns>影响行数</returns>
        public virtual int BatchInsert(IDbConnection dbConnection, string commandText, IEnumerable<T> sons)
        {
            return base.BatchInsert(dbConnection, commandText, sons);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="son">实例集合</param>
        /// <returns>影响行数</returns>
        public virtual int Delete(T son)
        {
            return base.Delete(son);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="dbConnection">Db Connection</param>
        /// <param name="son">实例集合</param>
        /// <returns>影响行数</returns>
        public virtual int Delete(IDbConnection dbConnection, T son)
        {
            return base.Delete(dbConnection, son);
        }

        /// <summary>
        /// 全部删除
        /// </summary>
        /// <returns></returns>
        public virtual int DeleteAll()
        {
            return base.DeleteAll<T>();
        }

        /// <summary>
        /// 编辑 如果GaeaSon实例Id 大于零Update 为零则Insert
        /// </summary>
        /// <param name="son">实例</param>
        /// <returns></returns>
        public virtual int Modify(T son)
        {
            if (son.Id <= 0)
            {
                return Insert(son);
            }
            else
            {
                return Update(son);
            }
        }

        /// <summary>
        /// 编辑 如果GaeaSon实例Id 大于零Update 为零则Insert 多用于事务
        /// </summary>
        /// <param name="dbConnection">Db Connection</param>
        /// <param name="son">实例</param>
        /// <returns></returns>
        public virtual int Modify(IDbConnection dbConnection, T son)
        {
            if (son.Id <= 0)
            {
                return Insert(dbConnection, son);
            }
            else
            {
                return Update(dbConnection, son);
            }
        }


    }
}
